using System;
using System.Linq;
using System.Reflection;

namespace Synergy.Reflection.Extensions
{
	/// <summary>
	/// Extension methods for the <see cref="AssemblyName"/> class.
	/// </summary>
	/// <remarks>
	///		<list type="table">
	///			<listheader><term>Version</term><description>Description</description></listheader>
	///			<item>
	///				<term>1.0</term>
	///				<description>Initial version</description>
	///			</item>
	///		</list>
	/// </remarks>
	public static class AssemblyNameExtension
	{
		/// <summary>
		/// Gets the public key token of the specified <paramref name="assemblyName"/> as a <see cref="String"/>.
		/// </summary>
		/// <param name="assemblyName">Unique identity of the assembly.</param>
		/// <returns>The public key token of the specified <paramref name="assemblyName"/>.</returns>
		public static string GetPublicKeyTokenString(this AssemblyName assemblyName)
		{
			if (assemblyName == null)
			{
				throw new ArgumentNullException("assemblyName");
			}

			var token = assemblyName.GetPublicKeyToken();
			return String.Join("", (from b in token select b.ToString("x2")).ToArray());
		}
	}
}